//
// Created by 123 on 2025/1/13.
//
#include "vector"
#include "algorithm"
#include "iostream"
#include "ctime"

void myPrint(int val){
    std::cout << val << " ";
}

void test1(){
    std::vector<int> v;
    v.push_back(50);
    v.push_back(20);
    v.push_back(10);
    v.push_back(30);
    v.push_back(40);

    //sort默认排序从小到大
    std::sort(v.begin(),v.end());
    std::for_each(v.begin(),v.end(), myPrint);
    std::cout << std::endl;

    //从大到小
    std::sort(v.begin(),v.end(),std::greater<int>());
    std::for_each(v.begin(),v.end(), myPrint);
    std::cout << std::endl;

    //打乱顺序
    srand((unsigned int)time(NULL));
    std::random_shuffle(v.begin(),v.end());
    std::for_each(v.begin(),v.end(), myPrint);
    std::cout << std::endl;
}

int main158(){
    test1();
    return 0;
}